package com.allwees.bs.core.model.order.wf.refund;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.allwees.core.wf.FsmState;
import com.allwees.core.wf.Transition;

import java.util.Arrays;
import java.util.List;

/**
 * 退货流程状态机
 *
 * @author yangylsky
 * @since 2019-09-17
 *
 */
public enum ERefundState implements FsmState<ERefundState, ERefundAction>, IEnum<String> {
	START("Start", false, false) {
		@Override
		public List<Transition<ERefundState, ERefundAction>> getTransitions() {
			return Arrays.asList(
				new Transition<>(ERefundAction.USER_REQUEST_REFUND, REFUND_REQUESTED),
				new Transition<>(ERefundAction.USER_REQUEST_REFUND_ON_LIMIT, COMPLETED),
				new Transition<>(ERefundAction.RETAILER_CANCEL_SHIPPED_ON_LIMIT, COMPLETED),
				new Transition<>(ERefundAction.RETAILER_CANCEL_SHIPPED_AFTER_LIMIT, COMPLETED),
				new Transition<>(ERefundAction.PLATFORM_CANCEL_SHIPPED, COMPLETED)
			);
		}
	},

	REFUND_REQUESTED("Request Refund", true, false) {
		@Override
		public List<Transition<ERefundState, ERefundAction>> getTransitions() {
			return Arrays.asList(
				new Transition<>(ERefundAction.USER_CANCEL_REFUND, USER_CANCELED),
				new Transition<>(ERefundAction.PLATFORM_AUDIT_REFUND_ACCEPT, COMPLETED),
				new Transition<>(ERefundAction.PLATFORM_AUDIT_REFUND_REJECT, REJECTED)
			);
		}
	},

	USER_CANCELED("User Canceled", false, true),

	//RETAILER_CANCEL_SHIPPED("Retailer Canceled", false, true), //这个是商家取消发货导致的退款,属于已退款状态

	//PLATFORM_CANCEL_SHIPPED("Platform Canceled", false, true), //这个是平台取消发货导致的退款,属于已退款状态

	REJECTED("REJECTED", false, true),

	COMPLETED("Refunded", false, true),

	REFUND_FAILED("Refund Failure",false,true);

	/**
	 * 状态描述
	 */
	private String desc;

	private boolean started;

	private boolean ended;

	@Override
	public boolean started() {
		return started;
	}

	@Override
	public boolean ended() {
		return ended;
	}

	public String getDesc() {
		return desc;
	}

	ERefundState(String desc, boolean started, boolean ended) {
		this.desc = desc;
		this.started = started;
		this.ended = ended;
	}

	/**
	 * 数据库存储用值
	 */
	@Override
	public String getValue() {
		return name();
	}
}
